package lessons.no7;

import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

public class N7_7 {
    public static void main(String[] args)throws Exception {
        RandomAccessFile infile = new RandomAccessFile("source/src.jpg","rw");
        FileChannel inChannel = infile.getChannel();
        RandomAccessFile outfile =new RandomAccessFile("target/dest.jpg","rw");
        FileChannel outChannel = outfile.getChannel();
        // 使用transferTo()方法进行整体复制
        long transferTo = inChannel.transferTo(0, inChannel.size(), outChannel);
        if(transferTo>0){
            System.out.println("复制成功!");
        }
        infile.close();
        inChannel.close();
        outfile.close();
        outChannel.close();

    }
}
